package com.eastfair.projectcore.controller;

import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.context.ContextConstants;
import com.eastfair.projectcore.dto.FunctionSaveDTO;
import com.eastfair.projectcore.entity.Function;
import com.eastfair.projectcore.entity.WorkerNode;
import com.eastfair.projectcore.dto.WorkerNodeSaveDTO;
import com.eastfair.projectcore.dto.WorkerNodeUpdateDTO;
import com.eastfair.projectcore.dto.WorkerNodePageQuery;
import com.eastfair.projectcore.service.WorkerNodeService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * DB 雪花id的 WorkerID
 * </p>
 *
 * @author ligang
 * @date 2022-02-25
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/workerNode")
@Api(value = "WorkerNode", tags = "DB 雪花id的 WorkerID")
public class WorkerNodeController extends SuperController<WorkerNodeService, Long, WorkerNode, WorkerNodePageQuery, WorkerNodeSaveDTO, WorkerNodeUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<WorkerNode> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<WorkerNode> workerNodeList = list.stream().map((map) -> {
            WorkerNode workerNode = WorkerNode.builder().build();
            //TODO 请在这里完成转换
            return workerNode;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(workerNodeList));
    }



    /**
     * 创建worknode
     * @return
     */
    @ApiOperation(value = "创建worknode", notes = "创建worknode")
    @PostMapping("/createWorkNode")
    public Long createFunction() {
        return baseService.createFunction();
    }



}
